//
//  NSDate+XKLConpareTime.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/5/6.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "NSDate+XKLConpareTime.h"

@implementation NSDate (XKLConpareTime)

-(NSDateComponents *)deltaFrom{
    
    //日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    //比较时间
    NSCalendarUnit unit = NSCalendarUnitDay | NSCalendarUnitMonth |NSCalendarUnitYear |NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
    return [calendar components:unit fromDate:self toDate:[NSDate date] options:0];
}

-(BOOL)isYear{
    //日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear fromDate:self toDate:[NSDate date] options:0];
    return components.year == 0;
}

-(BOOL)isYesterday{
    //日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth |NSCalendarUnitYear fromDate:self toDate:[NSDate date] options:0];
    
    return components.year == 0 && components.month == 0 &&components.day ==1;
}

-(BOOL)isToday{
    
    //日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth |NSCalendarUnitYear fromDate:self toDate:[NSDate date] options:0];
    
    return components.year == 0 && components.month == 0 &&components.day ==0;
}

@end
